package com.qidian.mes.defect.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.defect.mapper.DetectionMapper;
import com.qidian.mes.defect.mapper.TemplateMapper;
import com.qidian.mes.defect.service.TemplateService;
import com.qidianit.common.pojo.MESResult;
import com.qidianit.common.util.Constant;
import com.qidianit.mes.pojo.Detection;
import com.qidianit.mes.pojo.Template;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 泽华
 * @Description
 * @Time 2024-10-21 23:35
 */
@Service
public class TemplateServiceImpl implements TemplateService {
    @Autowired
    private TemplateMapper templateMapper;


    @Override
    public MESResult list(Long templateId, String templateName, String templateType, int page, int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Template> template = templateMapper.selectList(templateId,templateName,templateType);
        PageInfo<Template> pageInfo = new PageInfo<>(template);
        // 将pageInfo对象设置到MESResult中
        return MESResult.success(pageInfo);

    }

    @Override
    public MESResult save(Template template) {
        return templateMapper.insert(template) == 1?MESResult.success():MESResult.error();
    }

    @Override
    public MESResult delete(Long templateId) {
        Template template = new Template();
        template.setTemplateId(templateId);
        template.setTemplateStatus(Constant.DATA_STATUS_DELETE);
        return MESResult.isSuccess(templateMapper.deleteById(template));
    }

    @Override
    public MESResult update(Template template) {
        return MESResult.success(200,"ok",templateMapper.update(template));
    }

    @Override
    public MESResult selectById(Long templateId) {
        return MESResult.success(templateMapper.selectById(templateId));
    }
}
